package com.itheima.controller.v1;

import com.itheima.common.R;
import com.itheima.controller.v1.api.ActivityControllerApi;
import com.itheima.dto.ActivityDto;
import com.itheima.pojo.TbActivity;
import com.itheima.service.TbActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/activity")
@Slf4j
public class ActivityController implements ActivityControllerApi {
    @Autowired
    private TbActivityService tbActivityService;

    //活动分页展示接口
    @GetMapping("/list")
    public R list(ActivityDto activityDto) {
        log.info("活动分页展示接口");
        R r = tbActivityService.getActivityList(activityDto);
        return r;
    }

    //活动信息回显接口
    @GetMapping("/{id}")
    public R findById(@PathVariable Long id) {
        R r = tbActivityService.findById(id);
        return r;
    }

    //活动修改接口
    @PostMapping("/update")
    public R modify(@RequestBody TbActivity tbActivity) {
        R r = tbActivityService.modify(tbActivity);
        return r;
    }

    //活动删除接口
    @DeleteMapping("/{id}")
    public R remove(@PathVariable Long id) {
        R r = tbActivityService.remove(id);
        return r;
    }

    //审核通过接口
    @PostMapping("/pass/{id}")
    public R passActivity(@PathVariable Long id) {
        R r = tbActivityService.passActivity(id);
        return r;
    }

    //审核驳回接口
    @PostMapping("/reject/{id}")
    public R reject(@PathVariable Long id) {
        R r = tbActivityService.reject(id);
        return r;
    }

    //活动添加接口
    @PostMapping
    public R add(@RequestBody TbActivity tbActivity) {
        R r = tbActivityService.add(tbActivity);
        return r;
    }
}
